/**
 * 
 * @description Create any variable
 * @see         'edu.cmu.cs.stage3.alice.authoringtool.util.GroupingPanel' (extends) and 'edu.cmu.cs.stage3.alice.authoringtool.util.GUIElement' (implements)
 * @see         'edu.cmu.cs.stage3.alice.authoringtool.viewcontroller.VariableDnDPanel'
 * 
 * @author Jason Pratt
 */

package edu.cmu.cs.stage3.alice.authoringtool.viewcontroller;

import edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool;

public class VariableGUI extends edu.cmu.cs.stage3.alice.authoringtool.util.GroupingPanel implements edu.cmu.cs.stage3.alice.authoringtool.util.GUIElement {

 protected VariableDnDPanel variableDnDPanel;
 protected javax.swing.JComponent variableViewController;
 protected javax.swing.JLabel equalsLabel = new javax.swing.JLabel( " = " );

 public VariableGUI () {
  setLayout( new javax.swing.BoxLayout( this, javax.swing.BoxLayout.X_AXIS ) );
  setOpaque( false );
  setBorder( null );
  //T System.out.println("VariableGUI.java: VariableGUI()");
  }

 public void set (AuthoringTool authoringTool, edu.cmu.cs.stage3.alice.core.Variable variable, boolean includeDefaults, edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory factory) {
  clean();
  variableDnDPanel = edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getVariableDnDPanel( variable );
  variableViewController = edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getPropertyViewController( variable.value, includeDefaults, false, true, factory );
  add( variableDnDPanel );
  add( equalsLabel );
  add( variableViewController );
  add( javax.swing.Box.createHorizontalGlue() );
  //T String str = variableDnDPanel!=null ? variableDnDPanel.getNameLabel() : "<null>";
  //T System.out.println("VariableGUI.java: set(...): variableDnDPanel.nameLabel="+str);
  }

 public void goToSleep () {}
 public void wakeUp () {}

 public void clean () {
  removeAll();
  if (variableDnDPanel != null) {
   variableDnDPanel.release();
   }
  if (variableViewController instanceof edu.cmu.cs.stage3.alice.authoringtool.util.Releasable) {
   ((edu.cmu.cs.stage3.alice.authoringtool.util.Releasable)variableViewController).release();
   }
  variableDnDPanel = null;
  variableViewController = null;
  }

 public void die () {
  clean();
  }

 //Rem @Override
 public void release () {
  edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.releaseGUI( this );
  }

 //Rem @Override
 public void remove (java.awt.Component c) {
  super.remove( c );
  }

 }
